﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductTypeCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductTypeCommandHandler
{
    public class ProductTypeIsUpdateCommandHandler : IRequestHandler<ProductTypeIsUpdateCommand, int>
    {
        private readonly IProductTypeRepository _repository;
        public ProductTypeIsUpdateCommandHandler(IProductTypeRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 修改产品类别
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductTypeIsUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = await _repository.Update(new Domain.Product.ProductType()
            {
                ProductTypeId = request.ProductTypeId,
                ProductTypeNo = request.ProductTypeNo,
                ProductTypeName = request.ProductTypeName,
                ProductSuperior =request.ProductSuperior,
                ProductRemarks = request.ProductRemarks,
                DeleteTime = request.DeleteTime,
                DeleteName = request.DeleteName,
                CreateName = request.CreateName,
                CreateTime = request.CreateTime,
                UpdateName ="admin",
                UpdateTime = DateTime.Now,
                IsDelete = false,
            });
            return list;
        }
    }
}
